package com.xuanyuanxinyu.utils.net;

import com.xuanyuanxinyu.utils.LogUtils;

/**
 * @author tanzh
 */
public class NetworkCheckUtils {

    public static boolean isInSameRouter(String phoneIp, String deviceIp) {
        if (null == phoneIp || null == deviceIp) {
            return false;
        }
        try {
            int phoneIpIndex = phoneIp.lastIndexOf(".");
            String subPhoneIp = phoneIp.substring(0, phoneIpIndex);
            int deviceIpIndex = deviceIp.lastIndexOf(".");
            String subDeviceIp = deviceIp.substring(0, deviceIpIndex);
            return subDeviceIp.equals(subPhoneIp);
        } catch (Exception e) {
            LogUtils.logError("isInSameRouter" + e);
        }
        return false;
    }

    /**
     * str2 里面有多少个字符 在str1 里面
     *
     * @param str1
     * @param str2
     * @return
     */
    public static boolean compareStringSsim(String str1, String str2) {
        if (null == str1 || null == str2) {
            return false;
        }
        return str1.equals(str2);
//        int str1Len = str1.length();
//        int str2Len = str2.length();
//        double containsCount = 0;
//        for (int index = 0; index < str2Len; index++) {
//            String item = str2.substring(index, index + 1);
//            String item2 = index < str1Len ? str1.substring(index, index + 1) : null;
//            if (item.equals(item2)) {
//                containsCount += 1;
//            }
//        }
//        return containsCount == str2Len;
    }

    public static boolean compareStringSsimLow(String str1, String str2) {
        if (null == str1 || null == str2) {
            return false;
        }
        int str1Len = str1.length();
        int str2Len = str2.length();
        double containsCount = 0;
        for (int index = 0; index < str2Len; index++) {
            String item = str2.substring(index, index + 1);
            String item2 = index < str1Len ? str1.substring(index, index + 1) : null;
            if (item.equals(item2)) {
                containsCount += 1;
            }
        }
        return containsCount / str1Len > 0.6;
    }
}
